package com.wl.designpattern.singleton;

/**
 * 单例模式 （懒汉）
 *
 * 延迟加载和线程安全
 *
 * 优点：懒加载，线程安全，效率较高
 * 缺点：volatile影响一点性能，高并发下有一定的缺陷，某些情况下DCL会失效，虽然概率较小。
 *
 * Created by wangliang on 2021/2/22.
 */
public class SingletonLHan {
    private SingletonLHan() {}

    private static SingletonLHan instance;

    public static SingletonLHan getInstance() {
        if(null == instance) {
            synchronized (SingletonLHan.class) {
                if(null == instance) {
                    instance = new SingletonLHan();
                }
            }
        }

        return instance;
    }

}
